import Vue from 'vue'
import Vuex from 'vuex'
import * as actions from 'store/actions'
import * as getters from 'store/getters'
import * as types from 'store/mutation-types'

Vue.use(Vuex)

// global state
const state = {
    navs: [],
    token: '',
    userInfo: {},    // 当前登录用户的用户信息
}

const mutations = {
    [types.UPDATE_NAVS] (state, navs) {
        console.log("UPDATE_NAVS:"+navs)
        state.navs = navs || []
    },
    [types.UPDATE_TOKEN](state, token) {
        state.token = token || ''
    },
    [types.UPDATE_USER_INFO](state, userInfo) {
        state.userInfo = userInfo || {};
    }

}

export default new Vuex.Store({
    state,
    actions,
    getters,
    mutations,
    strict: process.env.NODE_ENV !== 'production'
})
